package me.firstapp.manage.advertisement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import me.firstapp.common.json.SingleObject;
import me.firstapp.common.module.bbs.JsonAdvertisement;
import me.firstapp.manage.common.BaseManage;
import me.firstapp.spi.bbs.AdvertisementService;

@Controller
@RequestMapping(value = "/advertisementManage")
public class AdvertisementManagePage extends BaseManage {

	@Autowired
	private AdvertisementService advertisementService;

	@Value("#{configProperties['qiniu.upload.domain']}")
	private String domain;

	@RequestMapping(value = "/advertisementList.html", method = RequestMethod.GET)
	public ModelAndView advertisementListView(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		return new ModelAndView("advertisment/advertismentList", modelMap);
	}

	@RequestMapping(value = "/advertisementAdd.html", method = RequestMethod.GET)
	public ModelAndView advertisementAddView(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		modelMap.put("domain", domain);
		return new ModelAndView("advertisment/advertismentAdd", modelMap);
	}

	@RequestMapping(value = "/advertisementUpdate.html", method = RequestMethod.GET)
	public ModelAndView advertisementUpdateView(Long id, HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		SingleObject<JsonAdvertisement> result = advertisementService.findAdvertisementById(id);
		modelMap.put("advertisement", result.getObject());
		modelMap.put("domain", domain);
		modelMap.put("id", id);
		return new ModelAndView("advertisment/advertismentUpdate", modelMap);
	}

}
